﻿// Bing Maps ASP.NEt Control is a community project available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// View the project and the latest code at http://BingMapsASP.codeplex.com

using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using Microsoft.Live.ServerControls.VE.Constants;

[assembly: WebResource("Microsoft.Live.ServerControls.VE.Extenders.CenterAndZoom.js", "text/javascript")]
[assembly: WebResource("Microsoft.Live.ServerControls.VE.Extenders.CenterAndZoom.debug.js", "text/javascript")]

namespace Microsoft.Live.ServerControls.VE.Extenders
{
    [ToolboxData(@"<{0}:CenterAndZoom ID=""CenterAndZoomExtender1"" runat=""server"" MapControlID="""" TargetControlID="""" ></{0}:CenterAndZoom>")]
    public sealed class CenterAndZoom : ExtenderBase
    {

        #region Properties

        /// <summary>
        /// The extender can either set just the center or the zoom level or both
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue(CenterAndZoomMode.CenterAndZoom)]
        [Description("The extender can either set just the center or the zoom level or both")]
        public CenterAndZoomMode Mode
        {
            get { return (CenterAndZoomMode)(ViewState[CenterAndZoomExtenderControlProperty.Mode] ?? CenterAndZoomMode.CenterAndZoom); }
            set
            {
                ViewState[CenterAndZoomExtenderControlProperty.Mode] = value;
            }
        }

        /// <summary>
        /// Optional, Sets the view of the map to the specified lat/long
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue("")]
        [Description("Optional, Sets the view of the map to the specified lat/long")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public LatLong Center
        {
            get { return (LatLong)(ViewState[CenterAndZoomExtenderControlProperty.Center] ?? new LatLong(0.0, 0.0)); }
            set
            {
                ViewState[CenterAndZoomExtenderControlProperty.Center] = value;
            }
        }

        /// <summary>
        /// Optional, Sets the view of the map to the specified zoom level
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue("1")]
        [Description("Optional, Sets the view of the map to the specified zoom level")]
        public int ZoomLevel
        {
            get { return (int)(ViewState[CenterAndZoomExtenderControlProperty.ZoomLevel] ?? 1); }
            set
            {
                ViewState[CenterAndZoomExtenderControlProperty.ZoomLevel] = value;
            }
        }

        #endregion


        #region ExtenderControl Members

        protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors(Control targetControl)
        {
            ScriptBehaviorDescriptor descriptor = new ScriptBehaviorDescriptor("Microsoft.Live.ClientControls.VE.Extenders.CenterAndZoom", targetControl.ClientID);
            descriptor.AddProperty(CenterAndZoomExtenderControlProperty.Mode, Mode);
            descriptor.AddProperty(CenterAndZoomExtenderControlProperty.Center, Center);
            descriptor.AddProperty(CenterAndZoomExtenderControlProperty.ZoomLevel, ZoomLevel);
            descriptor.AddProperty(ExtenderControlProperty.MapControlID, MapControlID);
            yield return descriptor;
        }

        protected override IEnumerable<ScriptReference> GetScriptReferences()
        {
            List<ScriptReference> descriptors = new List<ScriptReference>();
            descriptors.Add(new ScriptReference("Microsoft.Live.ServerControls.VE.Extenders.CenterAndZoom.js", GetType().Assembly.FullName));
            return descriptors;
        }

        #endregion
    }
}
